package book;

public class BOOK {
    static Object locker = new Object();
    static Object locker1 = new Object();
    static Object locker2 = new Object();
    static int a = 0;

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            synchronized (locker1) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (locker2) {

                }
            }
        });
        Thread t2 = new Thread(() -> {
            synchronized (locker2) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (locker1) {
                    
                }
            }
        });
        t1.start();
        t2.start();
    }

    public static void main1(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            synchronized (locker){
                synchronized (locker) {
                    synchronized (locker) {
                        synchronized (locker) {
                            for (int i = 0; i < 10000; i++) {

                                a++;
                            }
                        }
                    }
                }
            }
        });
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 10000; i++) {
                    a++;
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println("  a = "+ a+ "   ");
    }
}
